home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / SAT Invaders demo ƒ / sEnemy.c < prev    next >
Text File  |  1995-01-16  |  2KB  |  91 lines

  1. //• C translation from Pascal source file: sEnemy.p
  2.  
  3. //• ===============================================.
  4. //• ================= Enemy sprite unit ================.
  5. //• ===============================================.
  6.  
  7. //• Example file for Ingemars Sprite Animation Toolkit.
  8. //• © Ingemar Ragnemalm 1992.
  9. //• See doc files for legal terms for using this code.
  10.  
  11. //• sEnemy;
  12.  
  13. //• Sprite unit. A sprite unit should include the following routines:
  14. //• Init-procedure, that Initializes private bitmaps.
  15. //• Setup-procedure, that sets variables other than the standard ones set by MakeSprite.
  16. //• Handle-procedure, to be called once per iteration until the sprite dies.
  17. //• Hittask-procedure (optional), for advanced collission handling.
  18.  
  19. //• Enemy object for the SATInvaders sample game.
  20.  
  21. //• Prototypes, etc.
  22.  
  23. #include "SAT.h"
  24. #include "InvadeSAT.h"
  25. //    SAT, SoundConst, GameGlobals, sMissile;
  26.  
  27. extern void        InitMissile(void);
  28. extern pascal void        SetupMissile(SpritePtr sp);
  29. extern pascal void        HandleMissile(SpritePtr me);
  30.  
  31. Point globalSpeed;
  32. Boolean turnFlag;
  33. short last_H, downCount;
  34.  
  35. static FacePtr enemyFace[6];
  36.  
  37. void InitEnemy ()
  38. {
  39.     short ii;
  40.  
  41.     for (ii = 0; ii <  6; ii++)
  42.         enemyFace[ii] = SATGetFace (128 + ii);
  43. }
  44.  
  45. pascal void SetupEnemy (SpritePtr sp)
  46. {
  47.     sp->face = enemyFace[0];
  48.     sp->mode = SATRand (6);     //• icon number.
  49.     SetRect (&(sp->hotRect), 2, 4, 30, 32);
  50.     //• Since enemies are only created at the beginning of each level, we re-Initialize this stuff here:
  51.     globalSpeed.h = 0;
  52.     globalSpeed.v = 3;
  53.     turnFlag = true;
  54.     last_H = -5;
  55.     downCount = ((level / 2 + 1) * 40) / 3; //• How far down should we go when we come in?
  56.     sp->task = &HandleEnemy;
  57. }
  58.  
  59. pascal void HandleEnemy (SpritePtr me)
  60. {
  61.     SpritePtr missile;
  62.  
  63.     if (me->kind != -3)
  64.     {
  65.         me->task = 0L;
  66.         SATSoundPlay (dunkH, 1, false);
  67.     }
  68.     me->mode++;
  69.     if (me->mode == 6)
  70.         me->mode = 0;
  71.     me->face = enemyFace[me->mode];
  72.  
  73.     me->position.h = me->position.h + globalSpeed.h;
  74.     me->position.v = me->position.v + globalSpeed.v;
  75.  
  76.     if ((me->position.h < 0) || (me->position.h > gSAT.offSizeH - 32))
  77.         turnFlag = true;
  78.     if (me->position.v > gSAT.offSizeV)
  79.         me->task = 0L;
  80.  
  81.     if (SATRand (100) < 2)
  82.         {
  83.             missile = SATNewSprite (-1, me->position.h + 8, me->position.v + 20, &SetupMissile);
  84.             SATSoundPlay (piuH, 1, false);
  85.         }
  86. }
  87.  
  88.  
  89.  
  90.  
  91.